// import com.alibaba.druid.sql.ast.SQLCommentHint;
// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "OracleExitStatement.h"
#include "../../visitor/OracleASTVisitor.h"
#include "../../../../ast/SQLExpr.h"
#include "../../../../ast/SQLCommentHint.h"

SQLExpr_ptr OracleExitStatement::getWhen()
{
  return when;
}

void OracleExitStatement::setWhen(SQLExpr_ptr when)
{
  if (when != nullptr)
  {
    when->setParent(SharedObject(OracleExitStatement));
  }
  this->when = when;
}

// @Override
void OracleExitStatement::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleExitStatement)))
  {
    acceptChild(visitor, when);
  }
  visitor->endVisit(SharedObject(OracleExitStatement));
}

string_ptr OracleExitStatement::getLabel()
{
  return label;
}

void OracleExitStatement::setLabel(string_ptr label)
{
  this->label = label;
}

// @Override
SQLObject_ptr OracleExitStatement::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<OracleExitStatement>(new OracleExitStatement());
  std::shared_ptr<OracleExitStatement> x = std::dynamic_pointer_cast<OracleExitStatement>(clone_tmp);
  // OracleExitStatement x = new OracleExitStatement();

  x->setLabel(this->label);

  x->setAfterSemi(this->afterSemi);

  x->setDbType(this->dbType);

  if (when != nullptr)
  {
    x->setWhen(std::dynamic_pointer_cast<SQLExpr>(when->clone()));
  }

  if (this->headHints != nullptr)
  {
    SQLCommentHint_list_ptr headHintsClone = std::make_shared<std::list<SQLCommentHint_ptr>>();
    for (SQLCommentHint_ptr hint : *headHints)
    {
      SQLCommentHint_ptr h2 = std::dynamic_pointer_cast<SQLCommentHint>(hint->clone());
      h2->setParent(x);
      headHintsClone->push_back(h2);
    }
    x->setHeadHints(headHintsClone);
  }

  return x;
}
